package org.sxf.app.sign.utils;

import android.text.format.Time;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by mhy8958 on 2015/6/15.
 */
public class TimeUtils {

    public static String getStringDate() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
        String dateString = formatter.format(currentTime);
        return dateString;
    }

    public static String formatDateTime(String date){
        return date.substring(0,4)+"-"+date.substring(4,6)+"-"+date.substring(6,8)+" "+
                date.substring(8,10)+":"+date.substring(10,12)+":"+date.substring(12);
    }

    public static String formatDataTimeOnlyForTime(String date){
        try {
            return date.substring(8,10)+":"+date.substring(10,12);
        }catch (Exception e){
            return "";
        }
    }


    public static String getFormatDateTime() {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis());
    }
    public static String getNoneFormatTime(){
        return new SimpleDateFormat("yyyyMMddHHmmss").format(System.currentTimeMillis());
    }
    public static String getFormatDate(){
        return new SimpleDateFormat("yyyy-MM-dd").format(System.currentTimeMillis());
    }
    public static String getNoneFormatDate(){
        return new SimpleDateFormat("yyyyMMdd").format(System.currentTimeMillis());
    }
    public static int getYear(){
        Time time = new Time("GMT+8");
        time.setToNow();
        return time.year;
    }
    public static int getMonth(){
        //Time get month range [0,11]....Unbelievable
        Time time = new Time("GMT+8");
        time.setToNow();
        return time.month+1;
    }
    public static int getDay(){
        //Time get month range [0,11]....Unbelievable
        Time time = new Time("GMT+8");
        time.setToNow();
        return time.monthDay;
    }


    public static String formatDate(int year, int month, int day){
        return String.format("%d%02d%02d",year, month, day);
    }

    public static String formatDateForNotice(String date){
        try {
            String yyyyMMMdd = date.substring(0, 8);
            return yyyyMMMdd.substring(0,4) + "-" + yyyyMMMdd.substring(4,6) + "-" + yyyyMMMdd.substring(6,8);
        }catch (Exception e){
            return "";
        }
    }
}
